<?php

class EvaluationPhysiographicUnitsController extends AppController {

    var $name = 'EvaluationPhysiographicUnits';

    function index($appraisal_id) {
        $this->layout = "ajax";
        $this->set('appraisal_id', $appraisal_id);
        $this->set('unidades', $this->EvaluationPhysiographicUnit->find('all', array('conditions' => array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $appraisal_id), 'order' => array('EvaluationPhysiographicUnit.id'), 'fields' => array('EvaluationPhysiographicUnit.id', 'EvaluationPhysiographicUnit.area', 'EvaluationPhysiographicUnit.util', 'EvaluationPhysiographicUnit.valor_unitario', 'EvaluationPhysiographicUnit.clase_agrologica'))));
        $this->set('areaTotal', $this->EvaluationPhysiographicUnit->field('Sum(EvaluationPhysiographicUnit.area)', array('EvaluationPhysiographicUnit.evaluation_appraisal_id' => $appraisal_id)));
        $this->set('idProperty', $this->EvaluationPhysiographicUnit->EvaluationAppraisal->field('EvaluationAppraisal.property_id', array('EvaluationAppraisal.id' => $appraisal_id)));
        $this->set('areaAvaluo', $this->EvaluationPhysiographicUnit->EvaluationAppraisal->field('EvaluationAppraisal.area', array('EvaluationAppraisal.id' => $appraisal_id)));
    }

    function add($appraisal_id) {
        $this->layout = "ajax";
        $this->set('appraisal_id', $appraisal_id);
        if (!empty($this->data)) {
            if ($this->EvaluationPhysiographicUnit->saveAll($this->data)) {
                $this->Session->setFlash("Datos guardados correctamente");
                $this->redirect(array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'index', $appraisal_id));
            }
        }
    }

    function edit($id) {
        $this->layout = "ajax";
        if (empty($this->data)) {
            $this->EvaluationPhysiographicUnit->recursive = -1;
            $this->data = $this->EvaluationPhysiographicUnit->find('first', array('conditions' => array('EvaluationPhysiographicUnit.id' => $id)));
        } else {
            if ($this->EvaluationPhysiographicUnit->save($this->data)) {
                $this->Session->setFlash("Datos editados correctamente");
                $this->redirect(array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'index', $this->data['EvaluationPhysiographicUnit']['evaluation_appraisal_id']));
            }
        }
    }

    function delete($id, $appraisal_id) {
        if ($this->EvaluationPhysiographicUnit->delete($id)) {
            $this->Session->setFlash("Datos borrados correctamente");
            $this->redirect(array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'index', $appraisal_id));
        } else {
            $this->Session->setFlash("Error tratando de borrar dato por favor intente mas tarde ");
            $this->redirect(array('controller' => 'EvaluationPhysiographicUnits', 'action' => 'index', $appraisal_id));
        }
    }

}

?>
